<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline ">
                    <input type="text" name="name" requiredlay-verify="required" placeholder="请输入姓名"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-inline ">
                    <input type="text" name="username" required lay-verify="required" placeholder="请输入账号"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" required lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">辅助文字</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">职位</label>
                <div class="layui-input-inline">
                    <select name="position" lay-verify="required">
                        <option value=""></option>
                        <option value="0">开发岗位</option>
                        <option value="1">测试工程师</option>
                        <option value="2">前端开发</option>
                        <option value="3">部门主管</option>
                        <option value="4">行政</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">单选框</label>
                <div class="layui-input-block">
                    <input type="radio" name="gender" value="1" title="男">
                    <input type="radio" name="gender" value="0" title="女">
                </div>
            </div>
            <div class="layui-form-item  layui-footer" style="background-color: #fff">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSub">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
        <script src="/static/layui/layui.js"></script>
        <script>
            //Demo
            layui.use(['form', 'jquery'], function () {
                var form = layui.form;
                var $ = layui.$;
                //监听提交
                form.on('submit(formSub)', function (data) {
                    /* layer.msg(JSON.stringify(data.field));*/
                    $.ajax({
                        url: '/save',
                        method: 'post',
                        data: data.field,
                        success: function (data) {
                            if (data.code == 0) {
                                parent.layer.msg("添加成功!", {time: 500}, function () {
                                    //重新加载父页面
                                    parent.location.reload();
                                });
                                return;
                            } else {
                                layer.alert("添加失败")
                            }
                        },
                        error: function () {
                            layer.alert("添加失败")
                        }
                    });
                    return false;
                });
            });
        </script>

    </div>
</div>
</body>

</html>